﻿//-----------------------------------------------------------------------
// <copyright file="CountToVis.cs" company="Microsoft Corporation">
//     Copyright Microsoft Corporation. All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.) This is sample code only, do not use in production environments.
// </copyright>
//-----------------------------------------------------------------------
namespace Microsoft.ALMRangers.VsarTreasureMap.WindowsStoreApp.Converters
{
    using System;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Data;

    /// <summary>
    /// Converts an integer counter into a visibility and back.
    /// </summary>
    public class CountToVis : IValueConverter
    {
        /// <summary>
        /// Converts an integer to a visibility.  If the passed integer is 0, will return Visibility.Visible.
        /// </summary>
        /// <param name="value">Should be an integer value</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="language">The parameter is not used.</param>
        /// <returns>Visibility Enumerator Visible or Collapsed</returns>
        /// <exception cref="System.ArgumentException">Made a call to a function that converts an int to a visibility enum passing a non int as a value.;value</exception>
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (!value.GetType().Equals(typeof(int)))
            {
                throw new ArgumentException("Made a call to a function that converts an int to a visibility enum passing a non int as a value.", "value");
            }

            var @input = (int)value;
            return @input == 0 ? Visibility.Visible : Visibility.Collapsed;
        }

        /// <summary>
        /// Not Implemented
        /// </summary>
        /// <param name="value">The parameter is not used.</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="language">The parameter is not used.</param>
        /// <returns>The parameter is not used.</returns>
        /// <exception cref="System.NotImplementedException">Always throws this exception.</exception>
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new System.NotImplementedException();
        }
    }
}
